package cn.com.headfree.expert.service.impl;

import cn.com.headfree.entity.*;
import cn.com.headfree.expert.dao.IUserDataInfoDao;
import cn.com.headfree.expert.service.IUserDataInfoService;
import cn.com.headfree.util.SysDictionaryUtil;
import cn.com.headfree.vo.*;
import com.gta.edu.sdk.common.dto.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


@Service("IUserDataInfoService")
public class UserDataInfoServiceImpl implements IUserDataInfoService {
	@Autowired
	private IUserDataInfoDao userInfoDao;


	/**
	 * 上一年度绩效
	 *
	 * @param tYearEffectInfo
	 */

	@Override
	public List<TYearEffectInfo> findPageYearEffectByCondi(TYearEffectInfo tYearEffectInfo) {
		return  userInfoDao.findPageYearEffectByCondi( tYearEffectInfo);
	}
	public List<YearEffectVo> getYearEffectByErpNo(String erpNo, String mouldId, String ruleId, Integer years, String orgId, int index) {
		return userInfoDao.getYearEffectByErpNo(erpNo, mouldId, ruleId, years, orgId, index);
	}

	/**
	 * 教育培训
	 */
	@Override
	public List<TContiStudyInfo> findPageContiStudyInfoByCondi(TContiStudyInfo tContiStudyInfo) {
		return userInfoDao.findPageContiStudyInfoByCondi(tContiStudyInfo);
	}

	@Override
	public List<TSdtTutorPrentInfo> findPageSdtTutorPrentInfoByCondi(TSdtTutorPrentInfo tSdtTutorPrentInfo) {
		List<TSdtTutorPrentInfo> pageSdtTutorPrentInfoByCondi = userInfoDao.findPageSdtTutorPrentInfoByCondi(tSdtTutorPrentInfo);

		if (!pageSdtTutorPrentInfoByCondi.isEmpty()) {

			List<String> ids = new ArrayList<>();
			pageSdtTutorPrentInfoByCondi.forEach(i -> ids.add(i.getId()));
			List<TSdtPrentInfo> tSdtPrentInfoList = userInfoDao.getTSdtPrentInfoByMids(ids);

			if (!tSdtPrentInfoList.isEmpty()) {
				List<String> prentIds = new ArrayList<>();
				tSdtPrentInfoList.forEach(i -> prentIds.add(i.getId()));
				List<TSdtAward> tSdtAwardList = userInfoDao.getTSdtAwardByMids(prentIds);

				for (TSdtTutorPrentInfo tutorPrentInfo : pageSdtTutorPrentInfoByCondi) {
					List<TSdtPrentInfo> tSdtPrentInfos = new ArrayList<>();
					for (TSdtPrentInfo tSdtPrentInfo : tSdtPrentInfoList) {

						if (!tSdtAwardList.isEmpty()) {
							List<TSdtAward> tSdtAwards = new ArrayList<>();
							for (TSdtAward tSdtAward : tSdtAwardList) {
								if (tSdtAward.getSdtTdId().equals(tSdtPrentInfo.getId())) {
									tSdtAwards.add(tSdtAward);
								}
							}

							tSdtPrentInfo.settSdtAwardList(tSdtAwards);
						}

						if (tutorPrentInfo.getId().equals(tSdtPrentInfo.getSdtId())) {
							tSdtPrentInfos.add(tSdtPrentInfo);
						}
					}

					tutorPrentInfo.settSdtPrentInfo(tSdtPrentInfos);
				}
			}
		}
		return pageSdtTutorPrentInfoByCondi;

	}


	@Override
	public List<THonorInfo> findPageHonorInfoByCondi( THonorInfo tHonorInfo) {
		return userInfoDao.findPageHonorInfoByCondi( tHonorInfo);
	}


	@Override
	public List<TAcadeAchiveInfoVo> findPageAcadeAchiveInfoByCondi( TAcadeAchiveInfo tAcadeAchiveInfo) {
		List<TAcadeAchiveInfoVo> tAcadeAchiveInfoVos=userInfoDao.findPageAcadeAchiveInfoByCondi(tAcadeAchiveInfo);
//		if(!tAcadeAchiveInfoVos.isEmpty()){
//			Set<String> ids=new HashSet<>();
//			tAcadeAchiveInfoVos.forEach(i->ids.add(i.getId()));
//			List<TPartRank> tPartRankList = userInfoDao.getTPartRankByMids(ids, "12");
//			if(!tPartRankList.isEmpty()){
//				for(TAcadeAchiveInfoVo tAcadeAchiveInfoVo:tAcadeAchiveInfoVos){
//					List<TPartRank> tPartRankListVo=new ArrayList<>();
//					for(TPartRank tPartRank:tPartRankList){
//						if(tAcadeAchiveInfoVo.getId().equals(tPartRank.getItemId())){
//							tPartRankListVo.add(tPartRank);
//						}
//					}
//
//					tAcadeAchiveInfoVo.settPartRankList(tPartRankListVo);
//				}
//			}
//		}
		return tAcadeAchiveInfoVos;

	}

	@Override
	public List<TStandInfoVo> findPageStandInfoByCondi( TStandInfo tStandInfo) {
		List<TStandInfoVo> tStandInfoVos=userInfoDao.findPageStandInfoByCondi(tStandInfo);
//		if (!tStandInfoVos.isEmpty()) {
//			Set<String> ids = new HashSet<>();
//			tStandInfoVos.forEach(i -> ids.add(i.getId()));
//			List<TPartRank> tPartRankList = userInfoDao.getTPartRankByMids(ids, "13");
//			if (!tPartRankList.isEmpty()) {
//				for (TStandInfoVo tStandInfoVo : tStandInfoVos) {
//					List<TPartRank> tPartRankListVo = new ArrayList<>();
//					for (TPartRank tPartRank : tPartRankList) {
//						if (tStandInfoVo.getId().equals(tPartRank.getItemId())) {
//							tPartRankListVo.add(tPartRank);
//						}
//					}
//
//					tStandInfoVo.settPartRankList(tPartRankListVo);
//				}
//			}
//		}
		return tStandInfoVos;
	}

	@Override
	public List<TTecStandardInfo> findPageTecStandardInfoByCondi(TTecStandardInfo tecStandardInfo){
		List<TTecStandardInfo>  tecStandardInfoVos=userInfoDao.findPageTecStandardInfoByCondi( tecStandardInfo);

//		if (!tecStandardInfoVos.isEmpty()) {
//
//			if (tecStandardInfoVos.isEmpty()) {
//				return tecStandardInfoVos;
//			}
//			Set<String> ids = new HashSet<>();
//			tecStandardInfoVos.forEach(i -> ids.add(i.getId()));
//			List<TPartRank> tPartRankList = userInfoDao.getTPartRankByMids(ids, "21");
//			if (!tPartRankList.isEmpty()) {
//				for (TTecStandardInfo tecStandardInfoVo : tecStandardInfoVos) {
//					List<TPartRank> tPartRankListVo = new ArrayList<>();
//					for (TPartRank tPartRank : tPartRankList) {
//						if (tecStandardInfoVo.getId().equals(tPartRank.getItemId())) {
//							tPartRankListVo.add(tPartRank);
//						}
//					}
//					tecStandardInfoVo.setStandardTypeStr(SysDictionaryUtil.getNameByValueForDefault("tecStandardType", tecStandardInfoVo.getStandardType()));
//					tecStandardInfoVo.settPartRankList(tPartRankListVo);
//				}
//			}
//		}
		return tecStandardInfoVos;
	}

	@Override
	public List<TTecInnovInfoVo> findPageTecInnovInfoByCondi(TTecInnovInfo tTecInnovInfo) {
		List<TTecInnovInfoVo> tTecInnovInfoVos=userInfoDao.findPageTecInnovInfoByCondi(tTecInnovInfo);
//		if (!tTecInnovInfoVos.isEmpty()) {
//			Set<String> ids = new HashSet<>();
//			tTecInnovInfoVos.forEach(i -> ids.add(i.getId()));
//			List<TPartRank> tPartRankList = userInfoDao.getTPartRankByMids(ids, "15");
//			if (!tPartRankList.isEmpty()) {
//				for (TTecInnovInfoVo tTecInnovInfoVo : tTecInnovInfoVos) {
//					List<TPartRank> tPartRankListVo = new ArrayList<>();
//					for (TPartRank tPartRank : tPartRankList) {
//						if (tTecInnovInfoVo.getId().equals(tPartRank.getItemId())) {
//							tPartRankListVo.add(tPartRank);
//						}
//					}
//
//					tTecInnovInfoVo.settPartRankList(tPartRankListVo);
//				}
//			}
//		}
		return tTecInnovInfoVos;
	}

	@Override
	public List<TTecManInnovVo> findPageTecManInnovByCondi(TTecManInnov tTecManInnov) {
		List<TTecManInnovVo> tTecManInnovVos=userInfoDao.findPageTecManInnovByCondi(tTecManInnov);
//		if (!tTecManInnovVos.isEmpty()) {
//			Set<String> ids = new HashSet<>();
//			tTecManInnovVos.forEach(i -> ids.add(i.getId()));
//			List<TPartRank> tPartRankList = userInfoDao.getTPartRankByMids(ids, "16");
//			if (!tPartRankList.isEmpty()) {
//				for (TTecManInnovVo tTecManInnovVo : tTecManInnovVos) {
//					List<TPartRank> tPartRankListVo = new ArrayList<>();
//					for (TPartRank tPartRank : tPartRankList) {
//						if (tTecManInnovVo.getId().equals(tPartRank.getItemId())) {
//							tPartRankListVo.add(tPartRank);
//						}
//					}
//
//					tTecManInnovVo.settPartRankList(tPartRankListVo);
//				}
//			}
//		}
		return tTecManInnovVos;
	}

	@Override
	public List<TPatentInfoVo> findPagePatentInfoByCondi( TPatentInfo tPatentInfo) {
		List<TPatentInfoVo> tPatentInfoVos = userInfoDao.findPagePatentInfoByCondi(tPatentInfo);
//		if (!tPatentInfoVos.isEmpty()) {
//			Set<String> ids = new HashSet<>();
//			tPatentInfoVos.forEach(i -> ids.add(i.getId()));
//			List<TPartRank> tPartRankList = userInfoDao.getTPartRankByMids(ids, "14");
//			if (!tPatentInfoVos.isEmpty()) {
//				for (TPatentInfoVo tPatentInfoVo : tPatentInfoVos) {
//					List<TPartRank> tPartRankVo = new ArrayList<>();
//					for (TPartRank tPartRank : tPartRankList) {
//						if (tPatentInfoVo.getId().equals(tPartRank.getItemId())) {
//							tPartRankVo.add(tPartRank);
//						}
//					}
//
//					tPatentInfoVo.settPartRankList(tPartRankVo);
//				}
//			}
//		}
		return tPatentInfoVos;
	}
}
